package gui;

import processing.core.PApplet;

public class Widget {
    // Widget parent class
	float x0, y0, width, height;
	boolean hidden;
	PApplet pa;
    int neutralColor, activeColor, highlightColor;
	int backgroundColor;
	String label;
		
	Widget(PApplet parentApplet, float[] r, Object... args) {
		pa = parentApplet;
		// x0 - x coordinate of upper left corner of widget
		x0 = r[0];
		// y0 - y coordinate of upper left corner of widget
		y0 = r[1];
		// dx - horizontal extent of widget
		width = r[2];
		// dy - vertical extent of widget
		height = r[3];
		
		// Widget label
		if (args.length > 0) label = (String)args[0];
		if (args.length > 1) neutralColor = ((Integer)args[1]).intValue();
		if (args.length > 2) activeColor = ((Integer)args[2]).intValue();

		// hidden is a flag to stop the GUI from drawing the widget
		hidden = false;		
	} 
	
	public void mousePressed() {
		// Stub function to specify what a widget should do on a mouse press event			
	}

	public void mouseClicked() {
		// Stub function to specify what a widget should do on a mouse click event			
	}

	public void mouseDragged() {
		// Stub function to specify what a widget should do on a mouse drag event			
	}

	public void mouseMoved() {
		// Stub function to specify what a widget should do on a mouse move event			
	}

	public void mouseReleased() {
		// Stub function to specify what a widget should do on a mouse release event			
	}

	public void keyPressed() {
		// Stub function to specify what a widget should do on a key press event						
	}
	
	public boolean over() {
		return ((pa.mouseX >= x0) && (pa.mouseX <= x0 + width) 
				 && (pa.mouseY >= y0) && (pa.mouseY <= y0 + height));
	}

	public float[] position() {
		float[] r = {x0, y0, width, height};
	    return r;
	}  
	
	public void hide() {
		hidden = true;
	}
	
	public void reveal() {
		hidden = false;
	}
	
	public void draw() {
		// draws a white rectangle over the widget's footprint						
	    pa.fill(255);
        pa.rect(x0, y0, width, height);
	}
		
}
